package com.zt.springcloud.controller;

import cloud.zt.springboot.utils.ResultUtils;
import cloud.zt.springboot.utils.TokenUtils;
import com.zt.springcloud.service.Impl.UserServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author RedReins
 * @version 1.0
 * @description: TODO
 * @date 2021/8/28 22:43
 */
@RestController
public class LogController {
    private static Logger log = LoggerFactory.getLogger(LogController.class);

    @Autowired
    private UserServiceImpl userService;

    @PostMapping("/login")
    public ResultUtils<?> doLogin(String username, String password,String code,String uuid)
    {
        log.info("用户名:{} 密码:{}",username,password);
        return userService.checkUser(username,password,code,uuid);
    }

    @PostMapping("/getUserInfo")
    public ResultUtils<?> getUserInfo() {
        String username = TokenUtils.getUsername();
        return ResultUtils.success(userService.getLoginUser(username));
    }
    @PostMapping("/logout")
    public ResultUtils<?> doLogout()
    {
        String token = TokenUtils.getToken();
        return userService.doLogout(token);
    }

}
